Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

177
Visualizações
What does "function(err, result)" in JavaScript

I don't understand what does this code do in JavaScript. Why it is used? As far as I know it is "callback" but how the data assigned to "result"? I've never seen an information explains that.

 var prompt = require('prompt');
 prompt.start();
 prompt.get(['name'], function (err, result) {
 console.log('  name: ' + result.name);
 });
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

When you run a function that uses the callback, all you're doing is giving it another function for it to run when it is done. In your case, you are giving the prompt.get function the "function (err, result) {...}" function. When prompt.get is done and wants to return some result, it will call this function that you gave it. The function, as you can see, has parameters that can be passed to it (in your case, err and result). When it runs the callback (just like running any other function), it will give it parameters that are then exposed to the callback function you gave it.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda